# -*- coding: utf-8 -*-
"""
@Time ： 2024/10/21 10:02
@Auth ： 周瑞东 Ryan.Zhou
@File ：hardware_manager.py
"""
from utils.global_state import GlobalState
from hal.hal_plantower_9103 import HALPlantower9103
from hal.hal_dht11 import HALDHT11

import threading

class HardwareManager:
    _instance = None
    _lock = threading.Lock()

    def __new__(cls):
        with cls._lock:
            if cls._instance is None:
                cls._instance = super(HardwareManager, cls).__new__(cls)
        return cls._instance

    def __init__(self):
        if not hasattr(self, 'initialized'):
            self.initialized = True
            # 在这里初始化硬件 HAL 的相关属性和设置
            '''
            注意警报灯固定是COM4
            '''
            # self.sound_light_alarm = SoundLightAlarm()

            # 不再使用拉升传感器hal,改为das controller 2
            # self.position_sensor = HalPositionSensor()

            self.__global_state = GlobalState()

            # self.usb5631 = HalUSB5631()
            self.hal_plantower_9103 = HALPlantower9103()
            self.hal_dht11 = HALDHT11()

            # print("Hardware HAL initialized.")
    
    def get_air_quality(self):
        return self.hal_plantower_9103.getAirQuality()
    
    def get_temp_humdi(self):
        return self.hal_dht11.read_dht11()

    